package com.nvc.homeplan;

import java.text.NumberFormat;


import android.app.*;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.*;
import android.widget.*;

public class HousePlanSearchPage  extends Activity 
{
    final KeyValue storiesArray[] = new KeyValue[7];
    final KeyValue bedArray[] = new KeyValue[8];
    final KeyValue bathArray[] = new KeyValue[14];
    final KeyValue garageArray[] = new KeyValue[5];
    final KeyValue foundationArray[] = new KeyValue[6]; 
    
    private String strLevel = "";
    private String strLowBeds = "";
    private String strHighBeds = "";
    private String strBaths = "";
    private String strGarages = "";
    private String strFoundation = "";
    
	
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        initArray();
        
        setContentView(R.layout.house_plan_search_page);

        
        
        Spinner sLevel = (Spinner)findViewById(R.id.level);
        ArrayAdapter<KeyValue> sLevelAdapter = new ArrayAdapter<KeyValue>(this, android.R.layout.simple_spinner_item,storiesArray );
        sLevelAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sLevel.setAdapter(sLevelAdapter);
        sLevel.setOnItemSelectedListener(
            new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                	KeyValue d = storiesArray[position];
                	strLevel = d.getValue();
                }
                public void onNothingSelected(AdapterView<?> parent) {
                }
            }
        );

        
        Spinner sLowBeds = (Spinner)findViewById(R.id.lowbeds);
        ArrayAdapter<KeyValue> sLowBedsAdapter = new ArrayAdapter<KeyValue>(this, android.R.layout.simple_spinner_item,bedArray );
        sLowBedsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sLowBeds.setAdapter(sLowBedsAdapter);
        sLowBeds.setOnItemSelectedListener(
            new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                	KeyValue d = bedArray[position];
                	strLowBeds = d.getValue();
                }
                public void onNothingSelected(AdapterView<?> parent) {
                }
            }
        );


        Spinner sHighBeds = (Spinner)findViewById(R.id.highbeds);
        ArrayAdapter<KeyValue> sHighBedsAdapter = new ArrayAdapter<KeyValue>(this, android.R.layout.simple_spinner_item,bedArray );
        sHighBedsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sHighBeds.setAdapter(sHighBedsAdapter);
        sHighBeds.setOnItemSelectedListener(
            new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                	KeyValue d = bedArray[position];
                	strHighBeds = d.getValue() ;
                    //valueTextView.setText( d.getValue() );
                }
                public void onNothingSelected(AdapterView<?> parent) {
                }
            }
        );
        
        
        Spinner sBaths = (Spinner)findViewById(R.id.baths);
        ArrayAdapter<KeyValue> sBathsAdapter = new ArrayAdapter<KeyValue>(this, android.R.layout.simple_spinner_item, bathArray );
        sBathsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sBaths.setAdapter(sBathsAdapter);
        sBaths.setOnItemSelectedListener(
            new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                	KeyValue d = bathArray[position];
                	strBaths = d.getValue();
                }
                public void onNothingSelected(AdapterView<?> parent) {
                }
            }
        );
        

        Spinner sGarages = (Spinner)findViewById(R.id.garbays);
        ArrayAdapter<KeyValue> sGaragesAdapter = new ArrayAdapter<KeyValue>(this, android.R.layout.simple_spinner_item, garageArray );
        sGaragesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sGarages.setAdapter(sGaragesAdapter);
        sGarages.setOnItemSelectedListener(
            new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                	KeyValue d = garageArray[position];
                	strGarages = d.getValue();
                    //valueTextView.setText( d.getValue() );
                }
                public void onNothingSelected(AdapterView<?> parent) {
                }
            }
        );
        

        
        Spinner sFoundation = (Spinner)findViewById(R.id.foun);
        ArrayAdapter<KeyValue> sFoundationAdapter = new ArrayAdapter<KeyValue>(this, android.R.layout.simple_spinner_item, foundationArray );
        sFoundationAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sFoundation.setAdapter(sFoundationAdapter);
        sFoundation.setOnItemSelectedListener(
            new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                	KeyValue d = foundationArray[position];
                	strFoundation = d.getValue();
                    //valueTextView.setText( d.getValue() );
                }
                public void onNothingSelected(AdapterView<?> parent) {
                }
            }
        );
        
        
        
        final Button button = (Button) findViewById(R.id.btnPlanSearch);
        button.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
            	int c_t_lowsqft = 1;
            	int c_t_highsqft = 99999;
            	EditText t_lowsqft = (EditText) findViewById(R.id.t_lowsqft);
            	EditText t_highsqft = (EditText) findViewById(R.id.t_highsqft);
            	
                if (!((t_lowsqft.getText() == null) || t_lowsqft.getText().toString().equals(""))) {
                	try {
                		c_t_lowsqft = Integer.parseInt(t_lowsqft.getText().toString());
                	} catch (Exception e) {};
                }
                if (!((t_highsqft.getText() == null) || t_highsqft.getText().toString().equals(""))) {
                	try {
                		c_t_highsqft = Integer.parseInt(t_highsqft.getText().toString());
                	} catch (Exception e) {};
                }

                
            	HomePlanApplication application = (HomePlanApplication) getApplication();
            	application.searchType = "";
            	application.searchUrlQueryString = "t_lowsqft=" + c_t_lowsqft + "&t_highsqft=" + c_t_highsqft + "&level=" + strLevel + "&lowbeds=" + strLowBeds + "&highbeds=" + strHighBeds + "&baths=" + strBaths + "&garbays=" + strGarages + "&foun=" + strFoundation + "&plantype=1";
            	
                Intent intent = new Intent(Constants.INTENT_ACTION_PLAN_LIST_PAGE);
                startActivity(intent);
            }
        });
        

    }
    
    private void initArray()
    {
        storiesArray[0] = new KeyValue( "Number of Stories","" );
        storiesArray[1] = new KeyValue( "One Storey","1" );
        storiesArray[2] = new KeyValue( "Two Storey","2" );
        storiesArray[3] = new KeyValue( "Three Storey","2" );
        storiesArray[4] = new KeyValue( "Split Level","869" );
        storiesArray[5] = new KeyValue( "Raised Ranch","870" );
        storiesArray[6] = new KeyValue( "-- Include All Plans --","" );
        
        bedArray[0] = new KeyValue( "ALL","");
        bedArray[1] = new KeyValue( "1","1");
        bedArray[2] = new KeyValue( "2","2");
        bedArray[3] = new KeyValue( "3","3");
        bedArray[4] = new KeyValue( "4","4");
        bedArray[5] = new KeyValue( "5","5");
        bedArray[6] = new KeyValue( "6","6");
        bedArray[7] = new KeyValue( "7","7");
 
        bathArray[0] = new KeyValue( "Number of Bathrooms","");
        bathArray[1] = new KeyValue( "1 Bathroom","1");
        bathArray[2] = new KeyValue( "2 Bathroom","2");
        bathArray[3] = new KeyValue( "3 Bathroom","3");
        bathArray[4] = new KeyValue( "4 Bathroom","4");
        bathArray[5] = new KeyValue( "5 Bathroom","5");
        bathArray[6] = new KeyValue( "6 Bathroom","6");
        bathArray[7] = new KeyValue( "7 Bathroom","7");
        bathArray[8] = new KeyValue( "8 Bathroom","8");
        bathArray[9] = new KeyValue( "9 Bathroom","9");
        bathArray[10] = new KeyValue( "10 Bathroom","10");
        bathArray[11] = new KeyValue( "11 Bathroom","11");
        bathArray[12] = new KeyValue( "12 Bathroom","12");
        bathArray[13] = new KeyValue( "-- Include All Plans --","");
 
        garageArray[0] = new KeyValue( "Garage Bays","");
        garageArray[1] = new KeyValue( "One Car","1");
        garageArray[2] = new KeyValue( "Two Car","2");
        garageArray[3] = new KeyValue( "Three Car or more","3");
        garageArray[4] = new KeyValue( "-- Include All Plans --","");

        foundationArray[0] = new KeyValue( "Foundation Type","");
        foundationArray[1] = new KeyValue( "Slab","Slab");
        foundationArray[2] = new KeyValue( "Crawlspace","Crawlspace");
        foundationArray[3] = new KeyValue( "Basement","Basement");
        foundationArray[4] = new KeyValue( "Post","Post");
        foundationArray[5] = new KeyValue( "-- Include All Plans --","");
        
    }
}